package com.example.testtouch2;

import java.util.List;

import javax.microedition.khronos.opengles.GL10;

import com.demo.androidgame.fx.Game;
import com.demo.androidgame.fx.Input.TouchEvent;
import com.demo.androidgame.fx.gl.Camera2D;
import com.demo.androidgame.fx.gl.SpriteBatcher;
import com.demo.androidgame.fx.impl.GLScreen;
import com.demo.androidgame.fx.math.OverlapTester;
import com.demo.androidgame.fx.math.Rectangle;
import com.demo.androidgame.fx.math.Vector2;


public class menuScreen extends GLScreen{
	 Camera2D guiCam;
	 SpriteBatcher batcher;
	
	 Vector2 touchPoint;
	 Rectangle playBounds;
	 Rectangle scoreBounds;
	 Rectangle DescriptionBounds;
	 static float init = 60.0f;
	 static boolean nfcCheck = false;
	public menuScreen(Game game) {
		  super(game);
	        guiCam = new Camera2D(glGraphics, 320, 480);
	        batcher = new SpriteBatcher(glGraphics, 100);
	        touchPoint = new Vector2();
	        playBounds = new Rectangle(120, 180, 400, 70);
	        scoreBounds = new Rectangle(120, 110, 400, 70);
	        DescriptionBounds = new Rectangle(120, 40, 400, 70);
	        
	}

	@Override
	public void update(float deltaTime) {
//		Settings.soundEnabled = false;
			Assets.music.stop();
		   List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
	        game.getInput().getKeyEvents();
	        
	        int len = touchEvents.size();
	        for(int i = 0; i < len; i++) {
	            TouchEvent event = touchEvents.get(i);                        
	            if(event.type == TouchEvent.TOUCH_UP) {
	                touchPoint.set(event.x, event.y);
	                guiCam.touchToWorld(touchPoint);
	                
	                if(OverlapTester.pointInRectangle(playBounds, touchPoint)) {
	                
	                    game.setScreen(new TestScreen(game));
	                    return;
	                }
	                if(OverlapTester.pointInRectangle(scoreBounds, touchPoint)) {
	                    game.setScreen(new HighscoresScreen(game));
	                    return;
	                }
	                if(OverlapTester.pointInRectangle(DescriptionBounds, touchPoint)) {
	          
	                    game.setScreen(new DescriptionScreen(game));
	                    return;
	                }
	
	}
	        }
	}

	@Override
	public void present(float deltaTime) {
		 GL10 gl = glGraphics.getGL();        
	        gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
	        guiCam.setViewportAndMatrices();
	        
	        gl.glEnable(GL10.GL_TEXTURE_2D);
		
	        batcher.beginBatch(Assets.background0);
	        batcher.drawSprite(160, 240, 320, 480, Assets.background0Region);
	        batcher.endBatch();
	        
	        gl.glEnable(GL10.GL_BLEND);
	        gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);   
	        
	        batcher.beginBatch(Assets.atlas);
	        
	        batcher.drawSprite(120, 200, 140, 40, Assets.mainMenu1);                         
	        batcher.drawSprite(120, 150, 140, 40, Assets.mainMenu2);
	        batcher.drawSprite(120, 100,  140, 40, Assets.mainMenu3);
	        
	        //nfc
	        if(nfcCheck == true){
	        batcher.drawSprite(260, 460, 60,  15, Assets.nfcversion);
	        }
	        batcher.endBatch();  
	        
	        
	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub
		
	}
	public void onBackPressed() {
	
	}

}
